package com.drg.center.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.drg.center.entity.DictDrgOperationPO;
import com.drg.center.mapper.DictDrgOperationMapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class DictDrgOperationDAO extends BaseDAO<DictDrgOperationMapper, DictDrgOperationPO> {

    public List<DictDrgOperationPO> searchNoMatchMedicalOperation(String search, List<String> list) {
        LambdaQueryWrapper<DictDrgOperationPO> queryWrapper = new LambdaQueryWrapper<>();
        if (CollectionUtils.isNotEmpty(list)) {
            if (StringUtils.isNotBlank(search)) {
                queryWrapper.and(wrapper -> wrapper.like(DictDrgOperationPO::getOperationCode, search).or().like(DictDrgOperationPO::getOperationName, search));
            }
            queryWrapper.notIn(DictDrgOperationPO::getOperationCode, list);
        } else {
            if (StringUtils.isNotBlank(search)) {
                queryWrapper.like(DictDrgOperationPO::getOperationCode, search).or().like(DictDrgOperationPO::getOperationName, search);
            }
        }
        queryWrapper.last("limit 0,20");
        return getBaseMapper().selectList(queryWrapper);
    }
}
